package cn.ulyer.common.jpa;

import cn.ulyer.common.utils.IdWorker;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.AbstractUUIDGenerator;
import org.springframework.stereotype.Component;

import java.io.Serializable;

@Component(value = "idWorker")
public class IdWorkerGenerator extends AbstractUUIDGenerator {

    @Override
    public Serializable generate(SharedSessionContractImplementor sharedSessionContractImplementor, Object o) throws HibernateException {
        return IdWorker.INSTANCE.nextId();
    }

    @Override
    public boolean supportsJdbcBatchInserts() {
        return true;
    }
}
